﻿using FastCloud.Base.Config;
using FastUtil.Log;
using Quartz;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace FastCloud.Base.Realization
{
    public class CloudSchedulerPlugin : ISchedulerPlugin
    {
        public Task Initialize(string pluginName, IScheduler scheduler, CancellationToken cancellationToken = default)
        {
            return Task.Factory.StartNew(() =>
            {
                string FloderPath = CloudUtil.GetContentPath()+ "/Logs";
                DirectoryInfo SystemLogDir = new DirectoryInfo(FloderPath);
                if (!SystemLogDir.Exists)
                {
                    SystemLogDir.Create();
                }
                LogUtil.WriteLog(CloudUtil.GetContentPath() + "/Logs/TaskScheduler", "log_", "任务调度器初始化!");
            });

        }

        public Task Shutdown(CancellationToken cancellationToken = default)
        {
            return Task.Factory.StartNew(() =>
            {
                LogUtil.WriteLog(CloudUtil.GetContentPath() + "/Logs/TaskScheduler", "log_", "任务调度器关闭!");

            });
        }

        public Task Start(CancellationToken cancellationToken = default)
        {
            return Task.Factory.StartNew(() =>
            {
                LogUtil.WriteLog(CloudUtil.GetContentPath() + "/Logs/TaskScheduler", "log_", "调度器开始运行!");
            });
        }
    }
}
